import type { PermissionCreateDto, PermissionUpdateDto, PermissionListDto, PermissionSingleDto } from "@/dtos/permission.dto";
import type { PageRequest } from "@/types";
import http from "@/utils/http";

/**
 * 获取权限列表
 * @param params - 分页参数
 * @returns 包含权限列表、总数和总页数的对象
 */
export function getPermissionListApi(params: PageRequest) {
  return http.get<any, { list: PermissionListDto[]; total: number; pages: number }>("/permissions", { params });
}

/**
 * 获取单个权限
 * @param permissionId - 权限ID
 * @returns 权限的详细信息
 */
export function getPermissionApi(permissionId: string) {
  return http.get<any, PermissionSingleDto>(`/permissions/${permissionId}`);
}

/**
 * 创建权限
 * @param data - 权限创建数据
 * @returns 创建成功的布尔值
 */
export function createPermissionApi(data: PermissionCreateDto) {
  return http.post<any, boolean>("/permissions", data);
}

/**
 * 更新权限
 * @param permissionId - 权限ID
 * @param data - 权限更新数据
 * @returns 更新成功的布尔值
 */
export function updatePermissionApi(permissionId: string, data: PermissionUpdateDto) {
  return http.put<any, boolean>(`/permissions/${permissionId}`, data);
}

/**
 * 删除权限
 * @param permissionId - 权限ID
 * @returns 删除成功的布尔值
 */
export function deletePermissionApi(permissionId: string) {
  return http.delete<any, boolean>(`/permissions/${permissionId}`);
}